package application

import (
	"context"
	"encoding/hex"
	"gitee.com/alex_li/rodinbell/custom"
	"gitee.com/alex_li/rodinbell/mq"
	"gitee.com/alex_li/rodinbell/reader"
	log "github.com/jeanphorn/log4go"
	"time"
)

func onData(data reader.TagInfo) {

	epc := hex.EncodeToString(data.EPC)

	if !RefreshCache(epc) {
		custom.OnData(data)
	}
}

func Run(ctx context.Context) {

	log.Info("Application start")
	defer func() {
		if err := recover(); err != nil {
			log.Info(err)
		}
	}()
	mq.StartIot()
	for {
		select {
		case <-ctx.Done():
			break
		default:
			startReader(ctx)
			time.Sleep(2*time.Second)
		}
	}
}

